unit check2_form;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls, ComCtrls,  fpjson, jsonparser, intf, nkTitleBar, BCButton, BCLabel;

type

  { TfrmCheck_2 }

  TfrmCheck_2 = class(TForm)
    BCButton1: TBCButton;
    BCLabel1: TBCLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    ls: TListView;
    Memo1: TMemo;
    nkTitleBar1: TnkTitleBar;
    Panel5: TPanel;
    Panel6: TPanel;
    Panel7: TPanel;
    Panel8: TPanel;
    procedure BCLabel1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    FKind: TnkImportKind;

  public
    procedure Log(AText:string);
    property Kind:TnkImportKind read FKind write FKind;//分析类型
    procedure do_Check_2(Sender:TObject);//进行职工基本医疗保险参保登记风险
    procedure do_check_21(Sender:TObject);//职工医疗保险补缴业务风险
    procedure do_check_3(Sender:TObject);//居民医疗保险参保登记办理风险
    procedure do_check_31(sender:TObject);//居民参保人员重复信息合并风险
    procedure do_check_4(sender:TObject);//职工医疗保险转出办理风险
    procedure do_check_6(sender:TObject);//学生居民医疗保险参保登记办理风险
    procedure do_check_7(sender:TObject);//居民慢性病办理风险
    procedure do_check_8(sender:TObject);//职工慢性病办理风险
    procedure do_check_9(sender:TObject);//城乡居民高血压、糖尿病办理风险
    procedure do_check_71(sender:TObject);//死亡居民享受慢病待遇风险
    procedure do_check_81(sender:TObject);//死亡职工享受慢病待遇风险
    procedure do_check_91(sender:TObject);//死亡居民享受两病待遇风险

    procedure FillList(ATablename,AShorKind:string);//填充列表
  end;

var
  frmCheck_2: TfrmCheck_2;

implementation

{$R *.frm}

uses
  datamodule;
{ TfrmCheck_2 }

procedure TfrmCheck_2.FormShow(Sender: TObject);
begin
  if FKind = TikZhigong then
  begin
    Label1.Caption:='职工基本医疗保险参保登记风险分析';
    BCButton1.OnClick:=@do_check_2;
    FillList('zhigong','职工基本医疗保险参保登记风险');
  end
  else
  if FKind = TikBujiao then
  begin
    Label1.Caption:='职工医疗保险补缴业务风险分析';
    BCButton1.OnClick:=@do_check_21;
    FillList('bujiao','职工医疗保险补缴业务风险');
  end
  else
  if FKind= TikJumin then
  begin
    Label1.Caption:='居民医疗保险参保登记办理风险分析';
    BCButton1.OnClick:=@do_check_3;
    FillList('jumin','居民医疗保险参保登记办理风险');
  end
  else
  if FKind = TikHebing then
  begin
    Label1.Caption:='居民参保人员重复信息合并风险分析';
    BCButton1.OnClick:=@do_check_31;
    FillList('jumin','居民参保人员重复信息合并风险');
  end
  else
  if FKind = TikZhuanchu then
  begin
    Label1.Caption:='职工医疗保险转出办理风险分析';
    BCButton1.OnClick:=@do_check_4;
    FillList('zhuanchu','职工医疗保险转出办理风险');
  end
  else
  if FKind = TikXuesheng then
  begin
    Label1.Caption:='学生居民医疗保险参保登记办理风险分析';
    BCButton1.OnClick:=@do_check_6;
    FillList('xuesheng','学生居民医疗保险参保登记办理风险');
  end
  else
  if FKind = tikManxingbing then
  begin
    Label1.Caption:='居民慢性病办理风险分析';
    BCButton1.OnClick:=@do_check_7;
    FillList('manxingbing','居民慢性病办理风险');
  end
  else
  if FKind = tikZhigongManxingbing then
  begin
    Label1.Caption:='职工慢性病办理风险分析';
    BCButton1.OnClick:=@do_check_8;
    FillList('zhigongmanxingbing','职工慢性病办理风险');
  end
  else
  if FKind = tikGaoxueya then
  begin
    Label1.Caption:='城乡居民高血压、糖尿病办理风险分析';
    BCButton1.OnClick:=@do_check_9;
    FillList('gaoxueya','城乡居民高血压、糖尿病办理风险');
  end
  else
  if FKind = tikSiwangjuminmanbing then
  begin
    Label1.Caption:='死亡居民享受慢病待遇风险分析';
    BCButton1.OnClick:=@do_check_71;
    FillList('manxingbing','死亡居民享受慢病待遇风险');
  end
  else
  if FKind = tikSiwangzhigongmanbing then
  begin
    Label1.Caption:='死亡职工享受慢病待遇风险分析';
    BCButton1.OnClick:=@do_check_81;
    FillList('zhigongmanxingbing','死亡职工享受慢病待遇风险');
  end
  else
  if FKind = tikSiwangliangbing then
  begin
    Label1.Caption:='死亡居民享受两病待遇风险分析';
    BCButton1.OnClick:=@do_check_91;
    FillList('gaoxueya','死亡居民享受两病待遇风险');
  end;
end;

procedure TfrmCheck_2.BCLabel1Click(Sender: TObject);
begin
  Close;
end;

procedure TfrmCheck_2.Log(AText: string);
begin
  Memo1.Lines.Add(AText);
  Memo1.Update;
  Application.ProcessMessages;
end;

procedure TfrmCheck_2.do_Check_2(Sender: TObject);
var
  mCount,mTotal:integer;
  mR:TnkReport;
  mJson:TJsonObject;
  i:integer;
  mDelete:boolean;
  mChecked:boolean;
  mYear,mMonth:integer;
begin
  //先检查有没有Checked项目
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;

  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析……');

  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='职工基本医疗保险参保登记风险';

      with dm.pubqryWork do
      begin
        Close;
        Sql.Clear;
        Sql.Add('select * from zhigong  where cyear=:cyear and cmonth=:cmonth');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        mTotal:=RecordCount;
        First;
        while not Eof do
        begin
          //检查统一信用号码c4长度和校验码
          if (Trim(FieldByName('c4').AsString)='') then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c3').AsString+'：社会保障号码缺失');
            mR.AddWarning(FieldByName('c4').AsString,'0');//'社会保障号码缺失为空');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c4').AsString,0);
            mR.AddDetail(FieldByName('c4').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //社会保障号码c4不为空，但长度不正确的记录
          if length(Trim(FieldByName('c4').AsString))<>18 then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c3').AsString+'：社会保障号码长度不足18位');
            mR.AddWarning(FieldByName('c4').AsString,'1');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c4').AsString,1);
            mR.AddDetail(FieldByName('c4').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //计算校验码
          if dm.CheckIDCardNumber(Trim(FieldByName('c4').AsString))=False then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c3').AsString+'：社会保障号码校验码错误');
            mR.AddWarning(FieldByName('c4').AsString,'2');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c4').AsString,2);
            mR.AddDetail(FieldByName('c4').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end;
          Next;
        end;
        //检查完毕
        Log('本次风险点数量：'+inttostr(mR.WarningCount));
        //保存分析结果
        dm.SaveFx(mR,mDelete,'职工基本医疗保险参保登记风险');
        dm.SaveAnalLog(Label1.Caption, 0, 0, mR.WarningCount, mR.TipsCount);
        dm.UpdateAnalCount;
        mR.Free;
      end;
    end;
  end;

  Log('----分析完毕----');
  BCButton1.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_21(Sender: TObject);
var
  mCount,mTotal:integer;
  mR:TnkReport;
  mJson:TJsonObject;
  i:integer;
  mDelete:boolean;
  mChecked:boolean;
  mYear,mMonth:integer;
begin
  //先检查有没有Checked项目
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;

  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析……');

  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='职工医疗保险补缴业务风险';
      with dm.pubqryWork do
      begin
        Close;
        Sql.Clear;
        Sql.Add('select * from bujiao where cyear=:cyear and cmonth=:cmonth');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        mTotal:=RecordCount;
        First;
        while not Eof do
        begin
          //检查统一信用号码c0长度和校验码
          if (Trim(FieldByName('c0').AsString)='') then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c1').AsString+'：社会保障号码缺失');
            mR.AddWarning(FieldByName('c0').AsString,'0');//'社会保障号码缺失为空');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,0);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //社会保障号码c0不为空，但长度不正确的记录
          if length(Trim(FieldByName('c0').AsString))<>18 then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c1').AsString+'：社会保障号码长度不足18位');
            mR.AddWarning(FieldByName('c0').AsString,'1');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,1);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //计算校验码
          if dm.CheckIDCardNumber(Trim(FieldByName('c0').AsString))=False then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c1').AsString+'：社会保障号码校验码错误');
            mR.AddWarning(FieldByName('c0').AsString,'2');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,2);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end;
          Next;
        end;
        //检查完毕
        Log('本次风险点数量：'+inttostr(mR.WarningCount));
        //保存分析结果
        dm.SaveFx(mR,mDelete,'职工医疗保险补缴业务风险');
        dm.SaveAnalLog(Label1.Caption, 0, 0, mR.WarningCount, mR.TipsCount);
        dm.UpdateAnalCount;
        mR.Free;
      end;
    end;
  end;

  Log('----分析完毕----');
  BCButton1.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_3(Sender: TObject);
var
  mCount,mTotal:integer;
  mR:TnkReport;
  mJson:TJsonObject;
  i:integer;
  mDelete:boolean;
  mChecked:boolean;
  mYear,mMonth:integer;
begin
  //先检查有没有Checked项目
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;

  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析……');

  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='居民医疗保险参保登记办理风险';
      with dm.pubqryWork do
      begin
        Close;
        Sql.Clear;
        Sql.Add('select * from jumin where cyear=:cyear and cmonth=:cmonth');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        mTotal:=RecordCount;
        First;
        while not Eof do
        begin
          //检查统一信用号码c0长度和校验码
          if (Trim(FieldByName('c0').AsString)='') then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c1').AsString+'：社会保障号码缺失');
            mR.AddWarning(FieldByName('c0').AsString,'0');//'社会保障号码缺失为空');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,0);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //社会保障号码c0不为空，但长度不正确的记录
          if length(Trim(FieldByName('c0').AsString))<>18 then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c1').AsString+'：社会保障号码长度不足18位');
            mR.AddWarning(FieldByName('c0').AsString,'1');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,1);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //计算校验码
          if dm.CheckIDCardNumber(Trim(FieldByName('c0').AsString))=False then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c1').AsString+'：社会保障号码校验码错误');
            mR.AddWarning(FieldByName('c0').AsString,'2');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,2);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end;
          Next;
        end;
        //检查完毕
        Log('本次风险点数量：'+inttostr(mR.WarningCount));
        //保存分析结果
        dm.SaveFx(mR,mDelete,'居民医疗保险参保登记办理风险');
        dm.SaveAnalLog(Label1.Caption, 0, 0, mR.WarningCount, mR.TipsCount);
        dm.UpdateAnalCount;
        mR.Free;
      end;
    end;
  end;

  Log('----分析完毕----');
  BCButton1.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_31(sender: TObject);
var
  mCount,mTotal:integer;
  mR:TnkReport;
  mJson:TJsonObject;
  i:integer;
  mDelete:boolean;
  mChecked:boolean;
  mYear,mMonth:integer;
begin
  //先检查有没有Checked项目
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;

  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析……');

  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='居民参保人员重复信息合并风险';
      with dm.pubqryWork do
      begin
        Close;
        Sql.Clear;
        //        Sql.Add('SELECT * FROM jumin WHERE cyear=:cyear and cmonth=:cmonth and c0 IN (SELECT c0 FROM jumin GROUP BY c0 HAVING COUNT(c0)>1)');
        Sql.Add('SELECT * FROM jumin WHERE cyear=:cyear and cmonth=:cmonth and c0 IN (SELECT c0 FROM jumin where cyear=:cyear2 and cmonth=:cmonth2 GROUP BY c0 HAVING COUNT(c0)>1)');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Params.ParamByName('cyear2').AsInteger:=mYear;
        Params.ParamByName('cmonth2').AsInteger:=mMonth;
        Open;
        mTotal:=RecordCount;
        First;
        while not Eof do
        begin
          mR.WarningCount:=mR.WarningCount+1;
          Log('发现风险点，姓名'+FieldByName('c0').AsString+'：社会保障号码重复');
          mR.AddWarning(FieldByName('c0').AsString,'0');
          mJson:=TJsonObject.Create;
          mJson.Add(FieldByName('c0').AsString,0);
          mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
          mJson.Free;
          Next;
        end;
        //检查完毕
        Log('本次风险点数量：'+inttostr(mR.WarningCount));
        //保存分析结果
        dm.SaveFx(mR,mDelete,'居民参保人员重复信息合并风险');
        dm.SaveAnalLog(Label1.Caption, 0, 0, mR.WarningCount, mR.TipsCount);
        dm.UpdateAnalCount;
        mR.Free;
      end;
    end;
  end;

  Log('----分析完毕----');
  BCButton1.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_4(sender: TObject);
var
  mCount,mTotal:integer;
  mR:TnkReport;
  mJson:TJsonObject;
  i:integer;
  mDelete:boolean;
  mChecked:boolean;
  mYear,mMonth:integer;
begin
  //先检查有没有Checked项目
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;

  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析……');

  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='职工医疗保险转出办理风险';

      with dm.pubqryWork do
      begin
        Close;
        Sql.Clear;
        Sql.Add('select * from zhuanchu where cyear=:cyear and cmonth=:cmonth');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        mTotal:=RecordCount;
        First;
        while not Eof do
        begin
          //检查统一信用号码c0长度和校验码
          if (Trim(FieldByName('c5').AsString)='') then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c4').AsString+'：社会保障号码缺失');
            mR.AddWarning(FieldByName('c5').AsString,'0');//'社会保障号码缺失为空');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c5').AsString,0);
            mR.AddDetail(FieldByName('c5').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //社会保障号码c0不为空，但长度不正确的记录
          if length(Trim(FieldByName('c5').AsString))<>18 then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c4').AsString+'：社会保障号码长度不足18位');
            mR.AddWarning(FieldByName('c5').AsString,'1');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c5').AsString,1);
            mR.AddDetail(FieldByName('c5').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //计算校验码
          if dm.CheckIDCardNumber(Trim(FieldByName('c5').AsString))=False then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c4').AsString+'：社会保障号码校验码错误');
            mR.AddWarning(FieldByName('c5').AsString,'2');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c5').AsString,2);
            mR.AddDetail(FieldByName('c5').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end;
          Next;
        end;
        //检查完毕
        Log('本次风险点数量：'+inttostr(mR.WarningCount));
        //保存分析结果
        dm.SaveFx(mR,mDelete,'职工医疗保险转出办理风险');
        dm.SaveAnalLog(Label1.Caption, 0, 0, mR.WarningCount, mR.TipsCount);
        dm.UpdateAnalCount;
        mR.Free;
      end;
    end;
  end;

  Log('----分析完毕----');
  BCButton1.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_6(sender: TObject);
var
  mCount,mTotal:integer;
  mR:TnkReport;
  mJson:TJsonObject;
  i:integer;
  mDelete:boolean;
  mChecked:boolean;
  mYear,mMonth:integer;
begin
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;

  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析……');

  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='学生居民医疗保险参保登记办理风险';

      with dm.pubqryWork do
      begin
        Close;
        Sql.Clear;
        Sql.Add('select * from xuesheng where cyear=:cyear and cmonth=:cmonth');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        mTotal:=RecordCount;
        First;
        while not Eof do
        begin
          //检查统一信用号码c0长度和校验码
          if (Trim(FieldByName('c0').AsString)='') then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c1').AsString+'：社会保障号码缺失');
            mR.AddWarning(FieldByName('c0').AsString,'0');//'社会保障号码缺失为空');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,0);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //社会保障号码c0不为空，但长度不正确的记录
          if length(Trim(FieldByName('c0').AsString))<>18 then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c1').AsString+'：社会保障号码长度不足18位');
            mR.AddWarning(FieldByName('c0').AsString,'1');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,1);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          //计算校验码
          if dm.CheckIDCardNumber(Trim(FieldByName('c0').AsString))=False then
          begin
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c1').AsString+'：社会保障号码校验码错误');
            mR.AddWarning(FieldByName('c0').AsString,'2');//'代码长度不足18位');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,2);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end;
          Next;
        end;
        //检查完毕
        Log('本次风险点数量：'+inttostr(mR.WarningCount));
        //保存分析结果
        dm.SaveFx(mR,mDelete,'学生居民医疗保险参保登记办理风险');
        dm.SaveAnalLog(Label1.Caption, 0, 0, mR.WarningCount, mR.TipsCount);
        dm.UpdateAnalCount;
        mR.Free;
      end;
    end;
  end;

  Log('----分析完毕----');
  BCButton1.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_7(sender: TObject);
var
  mCount,mTotal:integer;
  mR:TnkReport;
  mJson:TJsonObject;
  i:integer;
  mDelete:boolean;
  mChecked:boolean;
  mYear,mMonth:integer;
  mObj:TnkManbingBianma;
  mNum:integer;
begin
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;
  //先再比对疾病编码，再比对医院编码等级
  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析……');
  //填充慢病编码医院级别对照对象
  mObj:=TnkManbingBianma.Create(nil);
  dm.FillManbingBianma('manbingbianma','yiyuanbianma',mObj);

  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='居民慢性病办理风险';

      with dm.pubqryWork do
      begin
        Close;
        Sql.Clear;
        Sql.Add('select * from manxingbing where cyear=:cyear and cmonth=:cmonth');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        mTotal:=RecordCount;
        First;
        while not Eof do
        begin
          mNum:=mObj.Check(FieldByName('c19').AsString,FieldByName('c15').AsString);
          if mNum=1 then
          begin
            //疾病编码不在目录
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c2').AsString+'疾病编码不在目录');
            mR.AddWarning(FieldByName('c0').AsString,'1');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,0);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          if mNum=2 then
          begin
            //医院编码不合规
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c2').AsString+'医院编码不合规');
            mR.AddWarning(FieldByName('c0').AsString,'2');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,0);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end;
          Next;
        end;
        //检查完毕
        Log('本次风险点数量：'+inttostr(mR.WarningCount));
        //保存分析结果
        dm.SaveFx(mR,mDelete,'居民慢性病办理风险');
        dm.SaveAnalLog(Label1.Caption, 0, 0, mR.WarningCount, mR.TipsCount);
        dm.UpdateAnalCount;
        mR.Free;
      end;
    end;
  end;

  mObj.Free;
  Log('----分析完毕----');
  BCButton1.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_8(sender: TObject);
var
  mCount,mTotal:integer;
  mR:TnkReport;
  mJson:TJsonObject;
  i:integer;
  mDelete:boolean;
  mChecked:boolean;
  mYear,mMonth:integer;
  mObj:TnkManbingBianma;
  mNum:integer;
begin
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;
  //先再比对疾病编码，再比对医院编码等级
  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析……');
  //填充慢病编码医院级别对照对象
  mObj:=TnkManbingBianma.Create(nil);
  dm.FillManbingBianma('zhigongmanbingbianma','yiyuanbianma',mObj);

  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='职工慢性病办理风险';

      with dm.pubqryWork do
      begin
        Close;
        Sql.Clear;
        Sql.Add('select * from zhigongmanxingbing where cyear=:cyear and cmonth=:cmonth');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        mTotal:=RecordCount;
        First;
        while not Eof do
        begin
          mNum:=mObj.Check(FieldByName('c19').AsString,FieldByName('c15').AsString);
          if mNum=1 then
          begin
            //疾病编码不在目录
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c2').AsString+'疾病编码不在目录');
            mR.AddWarning(FieldByName('c0').AsString,'1');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,0);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end
          else
          if mNum=2 then
          begin
            //医院编码不合规
            mR.WarningCount:=mR.WarningCount+1;
            Log('发现风险点，姓名'+FieldByName('c2').AsString+'医院编码不合规');
            mR.AddWarning(FieldByName('c0').AsString,'2');
            mJson:=TJsonObject.Create;
            mJson.Add(FieldByName('c0').AsString,0);
            mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
          end;
          Next;
        end;
        //检查完毕
        Log('本次风险点数量：'+inttostr(mR.WarningCount));
        //保存分析结果
        dm.SaveFx(mR,mDelete,'职工慢性病办理风险');
        dm.SaveAnalLog(Label1.Caption, 0, 0, mR.WarningCount, mR.TipsCount);
        dm.UpdateAnalCount;
        mR.Free;
      end;
    end;
  end;

  mObj.Free;
  Log('----分析完毕----');
  BCButton1.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_9(sender: TObject);
var
  mCount,mTotal:integer;
  mR:TnkReport;
  mJson:TJsonObject;
  i:integer;
  mDelete:boolean;
  mChecked:boolean;
  mYear,mMonth:integer;
begin
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;

  //先再比对疾病编码，再比对医院编码等级
  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析……');

  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='城乡居民高血压、糖尿病办理风险';

      with dm.pubqryWork do
      begin
        Close;
        Sql.Clear;
        Sql.Add('SELECT * FROM gaoxueya WHERE cyear=:cyear and cmonth=:cmonth and TRIM(c6) not in (select trim(c2) as c2 from yiyuanbianma where trim(c3)=:c31 or trim(c3)=:c32)');
        Params.ParamByName('c31').AsString:='1';
        Params.ParamByName('c32').AsString:='2';
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        mTotal:=RecordCount;
        First;
        while not Eof do
        begin
          //医院名称不在目录
          mR.WarningCount:=mR.WarningCount+1;
          Log('发现风险点，姓名'+FieldByName('c1').AsString+'备案医院不在目录');
          mR.AddWarning(FieldByName('c0').AsString,'1');
          mJson:=TJsonObject.Create;
          mJson.Add(FieldByName('c0').AsString,0);
          mR.AddDetail(FieldByName('c0').AsString,StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
          mJson.Free;
          Next;
        end;
        //检查完毕
        Log('本次风险点数量：'+inttostr(mR.WarningCount));
        //保存分析结果
        dm.SaveFx(mR,mDelete,'城乡居民高血压、糖尿病办理风险');
        dm.SaveAnalLog(Label1.Caption, 0, 0, mR.WarningCount, mR.TipsCount);
        dm.UpdateAnalCount;
        mR.Free;
      end;
    end;
  end;

  //查询出所有两病医院名称不符合医院级别的数据
  Log('----分析完毕----');
  BCButton1.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_71(sender: TObject);
var
  mChecked:boolean;
  i:integer;
  mYear,mMonth:integer;
  mR:TnkReport;
  mSiwangDate,mHuaboDate:TDate;
  mSiwangDate2:TDate;
  mDelete:boolean;
  mJson:TJsonObject;
begin
  //先检查有没有Checked项目
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;
  ls.Enabled:=False;
  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析死亡居民享受慢病待遇风险……');
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('==========================');
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='死亡居民享受慢病待遇风险分析';

      with dm.pubqryWork do
      begin
        Sql.Clear;
        Sql.Add('select * from manxingbing where cyear=:cyear and cmonth=:cmonth and c1 in (select c2 from siwang)');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        if RecordCount = 0 then
        begin
          Log('没有发现对死亡人居民享受慢病待遇数据。');
        end
        else
        begin
          Log('发现'+inttostr(RecordCount)+'条死亡人员享受待遇数据，正在继续分析……');
          First;
          while not Eof do
          begin
            Dm.GetSiwangDate(FieldByName('c1').AsString, mSiwangDate);
            Log('发现风险! '+FieldByName('c1').AsString+'死亡');
            mR.WarningCount:=mR.WarningCount+1;
            mR.AddWarning(FieldByName('c1').AsString,FormatDatetime('yyyy-mm-dd',mSiwangDate));
            //添加详细信息
            mJson:=TJsonObject.Create;
            mJson.Add('id', inttostr(FieldByName('id').AsInteger));
            mJson.Add('a0', FormatDatetime('yyyy-mm-dd', mSiwangDate));
            mJson.Add('c0', FieldByName('c0').AsString);
            mJson.Add('c1', FieldByName('c1').AsString);
            mJson.Add('c2', FieldByName('c2').AsString);
            mJson.Add('c3', FieldByName('c3').AsString);
            mJson.Add('c4', FieldByName('c4').AsString);
            mJson.Add('c5', FieldByName('c5').AsString);
            mJson.Add('c6', FieldByName('c6').AsString);
            mJson.Add('c8', FieldByName('c8').AsString);
            mJson.Add('c9', FieldByName('c9').AsString);
            mJson.Add('c10', FieldByName('c10').AsString);
            mJson.Add('c11', FieldByName('c11').AsString);
            mJson.Add('c12', FieldByName('c12').AsString);
            mJson.Add('c13', FieldByName('c13').AsString);
            mJson.Add('c14', FieldByName('c14').AsString);
            mR.AddDetail(FieldByName('c0').AsString, StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
            Next;
          end;
        end;
      end;
      Log('本月风险点数量：'+inttostr(mR.WarningCount));//+'  提示点数量：'+inttostr(mR.TipsCount));
      //保存分析结果
      dm.SaveFx(mR,mDelete,'死亡居民享受慢病待遇风险',True);
      dm.SaveAnalLog(Label1.Caption, mYear, mMonth, mR.WarningCount, mR.TipsCount);
      dm.UpdateAnalCount;
      mR.Free;
    end;
  end;
  Log('----分析完毕----');
  BCButton1.Enabled:=True;
  ls.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_81(sender: TObject);
var
  mChecked:boolean;
  i:integer;
  mYear,mMonth:integer;
  mR:TnkReport;
  mSiwangDate,mHuaboDate:TDate;
  mSiwangDate2:TDate;
  mDelete:boolean;
  mJson:TJsonObject;
begin
  //先检查有没有Checked项目
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;
  ls.Enabled:=False;
  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析死亡职工享受慢病待遇风险……');
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('==========================');
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='死亡职工享受慢病待遇风险分析';

      with dm.pubqryWork do
      begin
        Sql.Clear;
        Sql.Add('select * from zhigongmanxingbing where cyear=:cyear and cmonth=:cmonth and c1 in (select c2 from siwang)');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        if RecordCount = 0 then
        begin
          Log('没有发现对死亡职工享受慢病待遇数据。');
        end
        else
        begin
          Log('发现'+inttostr(RecordCount)+'条死亡人员享受待遇数据，正在继续分析……');
          First;
          while not Eof do
          begin
            Dm.GetSiwangDate(FieldByName('c1').AsString, mSiwangDate);
            Log('发现风险! '+FieldByName('c1').AsString+'死亡');
            mR.WarningCount:=mR.WarningCount+1;
            mR.AddWarning(FieldByName('c1').AsString,FormatDatetime('yyyy-mm-dd',mSiwangDate));
            //添加详细信息
            mJson:=TJsonObject.Create;
            mJson.Add('id', inttostr(FieldByName('id').AsInteger));
            mJson.Add('a0', FormatDatetime('yyyy-mm-dd', mSiwangDate));
            mJson.Add('c0', FieldByName('c0').AsString);
            mJson.Add('c1', FieldByName('c1').AsString);
            mJson.Add('c2', FieldByName('c2').AsString);
            mJson.Add('c3', FieldByName('c3').AsString);
            mJson.Add('c4', FieldByName('c4').AsString);
            mJson.Add('c5', FieldByName('c5').AsString);
            mJson.Add('c6', FieldByName('c6').AsString);
            mJson.Add('c8', FieldByName('c8').AsString);
            mJson.Add('c9', FieldByName('c9').AsString);
            mJson.Add('c10', FieldByName('c10').AsString);
            mJson.Add('c11', FieldByName('c11').AsString);
            mJson.Add('c12', FieldByName('c12').AsString);
            mJson.Add('c13', FieldByName('c13').AsString);
            mJson.Add('c14', FieldByName('c14').AsString);
            mR.AddDetail(FieldByName('c0').AsString, StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;
            Next;
          end;
        end;
      end;
      Log('本月风险点数量：'+inttostr(mR.WarningCount));//+'  提示点数量：'+inttostr(mR.TipsCount));
      //保存分析结果
      dm.SaveFx(mR,mDelete,'死亡职工享受慢病待遇风险',True);
      dm.SaveAnalLog(Label1.Caption, mYear, mMonth, mR.WarningCount, mR.TipsCount);
      dm.UpdateAnalCount;
      mR.Free;
    end;
  end;
  Log('----分析完毕----');
  BCButton1.Enabled:=True;
  ls.Enabled:=True;
end;

procedure TfrmCheck_2.do_check_91(sender: TObject);
var
  mChecked:boolean;
  i:integer;
  mYear,mMonth:integer;
  mR:TnkReport;
  mSiwangDate,mHuaboDate:TDate;
  mSiwangDate2:TDate;
  mDelete:boolean;
  mJson:TJsonObject;
begin
  //先检查有没有Checked项目
  mchecked:=False;
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      mchecked:=True;
      break;
    end;
  end;
  if mchecked=False then
  begin
    MessageDlg('请选择要分析的月份！',mtWarning,[mbOK],0);
    Exit;
  end;
  ls.Enabled:=False;
  BCButton1.Enabled:=False;
  Memo1.Lines.Clear;
  Log('开始分析死亡居民享受两病待遇风险……');
  for i:=0 to ls.Items.Count-1 do
  begin
    if ls.Items.Item[i].Checked then
    begin
      Log('==========================');
      Log('分析'+ls.Items.Item[i].Caption+'数据……');
      mYear:=strtoint(ls.Items.Item[i].SubItems.Strings[0]);
      mMonth:=strtoint(ls.Items.Item[i].SubItems.Strings[1]);
      mDelete:=Trim(ls.Items.Item[i].SubItems.Strings[2])='1';
      mR:=TnkReport.Create(Self);
      mR.CYear:=mYear;
      mR.CMonth:=mMonth;
      mR.TipsCount:=0;
      mR.WarningCount:=0;
      mR.Title:='死亡居民享受两病待遇风险分析';

      with dm.pubqryWork do
      begin
        Sql.Clear;
        Sql.Add('select * from gaoxueya where cyear=:cyear and cmonth=:cmonth and c0 in (select c2 from siwang)');
        Params.ParamByName('cyear').AsInteger:=mYear;
        Params.ParamByName('cmonth').AsInteger:=mMonth;
        Open;
        if RecordCount = 0 then
        begin
          Log('没有发现对死亡居民享受两病待遇数据。');
        end
        else
        begin
          Log('发现'+inttostr(RecordCount)+'条死亡人员享受待遇数据，正在继续分析……');
          First;
          while not Eof do
          begin
            Dm.GetSiwangDate(FieldByName('c0').AsString, mSiwangDate);
            Log('发现风险! '+FieldByName('c0').AsString+'死亡');
            mR.WarningCount:=mR.WarningCount+1;
            mR.AddWarning(FieldByName('c0').AsString,FormatDatetime('yyyy-mm-dd',mSiwangDate));
            //添加详细信息
{            mJson:=TJsonObject.Create;
            mJson.Add('id', inttostr(FieldByName('id').AsInteger));
            mJson.Add('a0', FormatDatetime('yyyy-mm-dd', mSiwangDate));
            mJson.Add('c0', FieldByName('c0').AsString);
            mJson.Add('c1', FieldByName('c1').AsString);
            mJson.Add('c2', FieldByName('c2').AsString);
            mJson.Add('c3', FieldByName('c3').AsString);
            mJson.Add('c4', FieldByName('c4').AsString);
            mJson.Add('c5', FieldByName('c5').AsString);
            mJson.Add('c6', FieldByName('c6').AsString);
            mJson.Add('c8', FieldByName('c8').AsString);
            mJson.Add('c9', FieldByName('c9').AsString);
            mJson.Add('c10', FieldByName('c10').AsString);
            mJson.Add('c11', FieldByName('c11').AsString);
            mJson.Add('c12', FieldByName('c12').AsString);
            mJson.Add('c13', FieldByName('c13').AsString);
            mJson.Add('c14', FieldByName('c14').AsString);
            mR.AddDetail(FieldByName('c0').AsString, StringReplace(mJson.AsJSON,'\','',[rfReplaceAll]));
            mJson.Free;  }
            Next;
          end;
        end;
      end;
      Log('本月风险点数量：'+inttostr(mR.WarningCount));//+'  提示点数量：'+inttostr(mR.TipsCount));
      //保存分析结果
      dm.SaveFx(mR,mDelete,'死亡居民享受两病待遇风险',True);
      dm.SaveAnalLog(Label1.Caption, mYear, mMonth, mR.WarningCount, mR.TipsCount);
      dm.UpdateAnalCount;
      mR.Free;
    end;
  end;
  Log('----分析完毕----');
  BCButton1.Enabled:=True;
  ls.Enabled:=True;
end;

procedure TfrmCheck_2.FillList(ATablename, AShorKind: string);
var
  mReports:string;
begin
  //填充待分析月份列表
  //获取以分析月份列表，组合成字符串
  with dm.pubqryWork do
  begin
    Sql.Clear;
    Sql.Add('select distinct cyear,cmonth from fxmaster where shortkind=:shortkind');
    Params.ParamByName('shortkind').AsString:=AShorKind;
    Open;
    First;
    mReports:='';
    while not Eof do
    begin
      mReports:=mReports+inttostr(FieldByName('cyear').AsInteger)+inttostr(FieldByName('cmonth').AsInteger)+';';
      Next;
    end;
  end;
  //获取划拨数据的月份列表
  ls.Items.BeginUpdate;
  ls.Items.Clear;
  with dm.pubqryWork do
  begin
    Sql.Clear;
    Sql.Add('select distinct cyear, cmonth from '+ATableName+' order by cyear desc, cmonth desc');
    Open;
    First;
    while not Eof do
    begin
      with ls.Items.Add do
      begin
        Caption:=inttostr(FieldByName('cyear').AsInteger)+'年'+inttostr(FieldByName('cmonth').AsInteger)+'月';
        SubItems.Add(inttostr(FieldByName('cyear').AsInteger));
        SubItems.Add(inttostr(FieldByName('cmonth').AsInteger));
        if Pos(SubItems.Strings[0]+SubItems.Strings[1], mReports) > 0 then
        begin
          SubItems.Add('1');
          ImageIndex:=1;
          Checked:=False;
        end
        else
        begin
          SubItems.Add('0');
          ImageIndex:=0;
          Checked:=True;
        end;
      end;
      Next;
    end;
  end;
  ls.Items.EndUpdate;
end;

end.

